﻿@model UserListModel
@using System.Globalization;

<style type="text/css">
    .laytable-cell-1-AvatarPictureUrl {
        height: 100%;
        max-width: 100%;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
            <div class="layui-form layui-form-pane layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">昵称</label>
                        <div class="layui-input-inline">
                            <input class="layui-input" name="SearchNickname" id="SearchNickname" placeholder="昵称" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">电话号码</label>
                        <div class="layui-input-inline">
                            <input class="layui-input" name="SearchPhone" id="SearchPhone" placeholder="电话号码" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">角色</label>
                        <div class="layui-input-inline">
                            <u-select asp-for="SearchUserRoleIds" asp-items="Model.AvailableUserRoles" />
                        </div>
                    </div>
                    <br />
                    <div class="layui-inline">
                        <label class="layui-form-label">公司</label>
                        <div class="layui-input-inline">
                            <input class="layui-input" name="SearchCompany" id="SearchCompany" placeholder="公司" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">电子邮箱</label>
                        <div class="layui-input-inline">
                            <input class="layui-input" name="SearchEmail" id="SearchEmail" placeholder="电子邮箱" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn" lay-submit lay-filter="LAY-app-contlist-search">搜索</button>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn  layui-btn-normal layuiadmin-btn-tags" data-type="add">添加</button>
                    </div>
                </div>
            </div>
        <div class="layui-card-body">
            <table id="LAY-user-list" lay-filter="LAY-user-list"></table>
            <script type="text/html" id="layuiadmin-app-cont-tagsbar">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>
</div>

<script type="text/html" id="activeTpl">
    <input type="checkbox" name="Active" lay-skin="switch" value="{{d.Id}}" lay-filter="active" lay-text="激活|停用" {{ d.Active ? 'checked' : ''}}>
</script>
<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
        }).use(['index', 'table'], function () {
            var index = layer.load(2, { shade: false });
            var table = layui.table
                , form = layui.form;
        //分类管理
        table.render({
            elem: '#LAY-user-list'
            , url: '@Html.Raw(Url.Action("ListJson"))' //模拟接口
            ,method:'post'
            , page: true //开启分页
            , even: true
            , limit: 15
            , limits: [15,30,50,100]
            , cols: [[
                { type: 'numbers' }
                , { field: 'Id', width: 100, title: 'ID' }
                , { field: 'AvatarPictureUrl', width: 110, style: 'height:80px;', title: '头像', templet: '<div><img height=80 src={{d.AvatarPictureUrl}}></div>' }
                , { field: 'Nickname', title: '昵称', minWidth: 100 }
                , { field: 'PhoneNumber', title: '电话', width: 120, align: 'center' }
                , { field: 'UserRoleNames', title: '用户角色名称', minWidth: 150 }
                , { field: 'Active', title: '激活', templet: '#activeTpl', width: 100, align: 'center' }
                , { field: 'LastActivityDate', title: '最近活跃', width: 180, align: 'center', templet: '<div>{{ layui.util.timeAgo(d.LastActivityDate) }}</div>' }
                , { title: '操作', width: 150, align: 'center',  toolbar: '#layuiadmin-app-cont-tagsbar' }
            ]]
            , id: 'testReload'
            , text: { none: '一条数据也没有^_^' }
            , done: function () {
                layer.close(index);
            }
            });
            //监听搜索
            layui.form.on('submit(LAY-app-contlist-search)', function (data) {
                var field = data.field;
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: field
                }, 'data');
            });
        //监听工具条
        table.on('tool(LAY-user-list)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定删除？', function (index) {
                    obj.del();
                    $.post('@Url.Action("Delete")', { id: obj.data.Id });
                    layer.close(index);
                });

            } else if (obj.event === 'edit') {
                var tr = $(obj.tr);
                window.location.href = '@Url.Action("Edit")?id=' + data.Id;
            }
        });

         //监听锁定操作
            form.on('switch(active)', function (obj) {
            var check = obj.elem.checked;
            $.post('@Url.Action("Active")', { Id: this.value, checked: check });
         })

        var $ = layui.$, active = {
            add: function () {
                window.location.href = '@Url.Action("Edit")';
            }
        }
        $('.layui-btn.layuiadmin-btn-tags').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>







